set encoding=utf-8

set modifiable

" set fileencodings=utf-8, cp936, gbk, gb18030,chinese,big5,iso-8859,latin1
filetype plugin indent on
" 行号
set nu
" 自动缩进
set autoindent
set smartindent
" set tab  to space
set expandtab
set smarttab
" read file's tab to 4 space
set tabstop=4
" when backspace, 4 space to 1 tab
set softtabstop=0
" set tab to 4 space width
set shiftwidth=4
" set exist tab to space
" retab!
" 搜索高亮
set hlsearch 
" 在输入要搜索的文字时，vim会实时匹配
set incsearch
" 高亮显示匹配的括号
set showmatch 
" 在被分割的窗口间显示空白，便于阅读
set fillchars=vert:\ ,stl:\ ,stlnc:\  
" 设置空白字符的视觉提示
"set list listchars=extends:❯,precedes:❮,tab:▷\ ,trail:◌
" 保存文件前建立备份，保存成功后删除该备份
set writebackup 
 "设置无备份文件
set nobackup 
set noswapfile
"滚动，光标下保持显示行数
set scrolloff=5
"鼠标功能
set mouse=a
"set selection=exclusive
" 光标竖横线
set cursorcolumn
set cursorline
" spell check
set spell spelllang=en_us,cjk
set nospell
" Yank text to the OS X clipboard" 将文本复制到OS X剪贴板中
 " set clipboard+=unnamedplus
"写作统计字数
function! WordCount()
    exec "%s/\\S//gn | noh"
endfunction
noremap wc :call WordCount()<CR>
"主题设置
set background=dark
let g:solarized_termcolors = 256
let g:solarized_termtrans = 1
colorscheme colors_lanio
"延迟
    set timeoutlen=400
"不换行
    set wrap

"im-select
    let g:input_cmd = "macism"
    let g:input_toggle = system(g:input_cmd)
    function! Normal()
        let g:input_toggle = system(g:input_cmd)
        let l:a = system(g:input_cmd." com.apple.keylayout.US")
    endfunction
    function! Insert()
        let l:a = system(g:input_cmd." ".g:input_toggle)
    endfunction
    autocmd InsertLeave * call Normal()
    autocmd InsertEnter * call Insert()

" filetype

"hi color
function s:verify_format_of_line(line)
	let l:re = matchlist(a:line, '\vctermbg[=]+\s*(\S*)\s*ctermfg[=]+\s*(\S*)\s*cterm[=]+\s*(\S*)')
    if empty(l:re)
        return []
    endif
    let ctermL = ['NONE']
    for idx in range(1,3)    
        if l:re[idx] == ''
            call add(ctermL, 'NONE')
        else
            call add(ctermL, l:re[idx])
        endif
    endfor 
	return ctermL
endfunction
function s:color_code_hl()
	let l:lines = getline('^', '$')
	let l:ns_id = nvim_create_namespace('color_code_hl_symbols')
	if bufexists(bufnr()) 
        call nvim_buf_clear_namespace(bufnr(), l:ns_id, 0, -1)
	endif
	for idx in range(len(l:lines))
        let l:re = s:verify_format_of_line(l:lines[idx])
        if empty(l:re)
            continue
        endif      
        let l:hiName = 'ColorCode_'.idx
        execute 'hi clear '.l:hiName
        execute 'hi def '.l:hiName.' ctermbg='.l:re[1].' ctermfg='.l:re[2].' cterm='.l:re[3]
        let l:name = matchlist(l:lines[idx], '\v(highlight|hi)\s+(\S+)')
        let [str, s, e] = matchstrpos(l:lines[idx], l:name[2])
	    call nvim_buf_add_highlight(bufnr(), l:ns_id, l:hiName, idx, s, e)
	endfor
endfunction
autocmd BufWritePost,BufEnter colors_lanio.vim call <SID>color_code_hl()

"vimdiff
set diffopt=context:3

"macro,播放宏的时候建议使用set lz
set nolz

"maxmempattern	mmp	模式匹配使用的最大内存 (以千字节计)
set mmp=2000

" set signcolumn=no "最左边的提示符号
